$(document).ready(function () {
//Facebook ready
	if(window.FB) {
	    facebookReady();
	  } else {
	    window.fbAsyncInit = facebookReady;
	  }
	
	function facebookReady(){			
		
		fbplugin.getLogin('checkUserLikeFP()');
		
	    
	  }

	  

	//MENU READY
	active =$('.active_selector').attr('id');
	if( active == 'videoduthi'){
		$('#selector').css({'left':'140px','top':'3px'});
	}else if( active == 'vongbanket'){
		$('#selector').css({'left':'250px','top':'-1px'});		
	}else if( active == 'vongchungket'){
		$('#selector').css({'left':'375px','top':'-1px'});		
	}else if( active == 'thelechuongtrinh'){
		$('#selector').css({'left':'525px','top':'10px'});	
	}

	//MENU HOVER ACTIVE 
	active =$('.active_selector').attr('id');
	if(active==null){
		$('#selector').css({'display':'none'});
	}
	$('#videoduthi').hover(function(){
		$('#selector').css({'left':'140px','top':'3px','display':'block'});
	},function(){
		if(active=='videoduthi'){
			$('#selector').css({'left':'140px','top':'3px'});
		}else if(active=='vongbanket'){
			$('#selector').css({'left':'250px','top':'-1px'});
		}else if(active=='vongchungket'){
			$('#selector').css({'left':'375px','top':'-1px'});	
		}else if(active=='thelechuongtrinh'){
			$('#selector').css({'left':'525px','top':'10px'});
		}else{
			$('#selector').css({'display':'none'});
		}
	});
	$('#vongbanket').hover(function(){
		$('#selector').css({'left':'250px','top':'-1px','display':'block'});
	},function(){
		if(active=='videoduthi'){
			$('#selector').css({'left':'140px','top':'3px'});
		}else if(active=='vongbanket'){
			$('#selector').css({'left':'250px','top':'-1px'});
		}else if(active=='vongchungket'){
			$('#selector').css({'left':'375px','top':'-1px'});	
		}else if(active=='thelechuongtrinh'){
			$('#selector').css({'left':'525px','top':'10px'});
		}else{
			$('#selector').css({'display':'none'});
		}
	});
	$('#vongchungket').hover(function(){
		$('#selector').css({'left':'375px','top':'-1px','display':'block'});
	},function(){
		if(active=='videoduthi'){
			$('#selector').css({'left':'140px','top':'3px'});
		}else if(active=='vongbanket'){
			$('#selector').css({'left':'250px','top':'-1px'});
		}else if(active=='vongchungket'){
			$('#selector').css({'left':'375px','top':'-1px'});	
		}else if(active=='thelechuongtrinh'){
			$('#selector').css({'left':'525px','top':'10px'});
		}else{
			$('#selector').css({'display':'none'});
		}
	});
	$('#thelechuongtrinh').hover(function(){
		$('#selector').css({'left':'525px','top':'10px','display':'block'});
		
	},function(){
		if(active=='videoduthi'){
			$('#selector').css({'left':'140px','top':'3px'});
		}else if(active=='vongbanket'){
			$('#selector').css({'left':'250px','top':'-1px'});
		}else if(active=='vongchungket'){
			$('#selector').css({'left':'375px','top':'-1px'});	
		}else if(active=='thelechuongtrinh'){
			$('#selector').css({'left':'525px','top':'10px'});
		}else{
			$('#selector').css({'display':'none'});
		}
	});

	//VIDEO LIKE INFO 
	$('#video_content a').hover(function(){
		$(this).find('.video_desc').css('opacity','1');
	},function(){
		$(this).find('.video_desc').css('opacity','0');
	})

	$('#videovongbanket_content a').hover(function(){
		$(this).find('.video_desc').css('opacity','1');
	},function(){
		$(this).find('.video_desc').css('opacity','0');
	})
	//WATER MARK INPUT 
	

	//VIDEO BACK BUTTON
	$('#back_button').click(function(){
		//goBack();
	});
	//WEEK CLICK LOADING
	$('.week_btn').click(function(){
		//$('#video_content').find('a').remove();
		$('#loading_video').css('display','block');
	})

	//VIDEO CLICK LOADING
	$('#video_content a').click(function(){
		$('.video_loading').remove();
		$(this).find('div[class="video"]').append("<div class='video_loading' ><img src='"+gULR+"/img/loader.gif' /> </div>");
	})

	//SEARCH CLICK LOADING 
	$('#search_button span').click(function(){			
		$(this).find('#search_loading').css('display','block');		
	})
	function goBack() {
    $(this).delay(1000, function(){
      history.back();})}
	//WEEK HOVER
	$('#week1').hover(function(){
		if($(this).find('img').hasClass('button_week_active'))
		{
			return;
		}else{			
			$(this).find('img').attr('src',gULR+'/img/button_week1_active.png');
		}
		
	},function(){
		if($(this).find('img').hasClass('button_week_active'))
		{
			return;
		}else{
			$(this).find('img').attr('src',gULR+'/img/button_week1.png');
		}
	})


	$('#week2').hover(function(){
		if($(this).find('img').hasClass('button_week_active'))
		{
			return;
		}else{
			$(this).find('img').attr('src',gULR+'/img/button_week2_active.png');
		}
		
	},function(){
		if($(this).find('img').hasClass('button_week_active'))
		{
			return;
		}else{
			$(this).find('img').attr('src',gULR+'/img/button_week2.png');
		}
	})

	$('#week3').hover(function(){
		if($(this).find('img').hasClass('button_week_active'))
		{
			return;
		}else{
			$(this).find('img').attr('src',gULR+'/img/button_week3_active.png');
		}
		
	},function(){
		if($(this).find('img').hasClass('button_week_active'))
		{
			return;
		}else{
			$(this).find('img').attr('src',gULR+'/img/button_week3.png');
		}
	})
	

	$('#week4').hover(function(){
		if($(this).find('img').hasClass('button_week_active'))
		{
			return;
		}else{
			$(this).find('img').attr('src',gULR+'/img/button_week4_active.png');
		}
		
	},function(){
		if($(this).find('img').hasClass('button_week_active'))
		{
			return;
		}else{
			$(this).find('img').attr('src',gULR+'/img/button_week4.png');
		}
	})	

})

function disableMenu(){
	
	$("ul.wrapper").css("display","none");
	
}
function enableMenu(){
	$("ul.wrapper").css("display","block");	
}
function checkUserLikeFP(){
		//check user like fanpage
		FB.api('/me/likes/'+fbplugin.FPID,{access_token : fbplugin.access_token}, function(response) {			
		   	 if(response.data!=undefined && response.data.length>0){
		   		 fbplugin.isUserlikeFP=true;		   		
		   	 }
		   	 else{
		   		if(currenturl!=window.location.origin+apppath && currenturl!=window.location.origin+apppath+'the-le/'){		   			
		   			redirect='?r='+currenturl.replace(window.location.origin+apppath,'');
		   			//window.location=window.location.origin+apppath+redirect;					
				}		   		
		   	 }
		   	$(document).trigger("facebook:ready");
		    });	  
	}
	function showLikedWithCount(likecount){
		var showstring="";
		if(likecount>0)showstring="và "+likecount+" người ";
		
		
		if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1){					
			$('#votecontent').html("<div id='voted_button'><span id='liked_button' style='padding:6px 8px 1px'>Bạn <span id='ortherlikecount'>"+showstring+"</span> đã bình chọn</span></div><span id='share_button' style='position: relative;top: 5px;cursor:pointer;z-index:14;margin-left: 10px;'><img src='"+gULR+"/img/sharebt.png' alt=''/></span>");
		}
		else{
			$('#votecontent').html("<div id='voted_button'><span id='liked_button'>Bạn <span id='ortherlikecount'>"+showstring+"</span> đã bình chọn</span></div><span id='share_button' style='position: relative;top: 5px;cursor:pointer;z-index:14;margin-left: 10px;'><img src='"+gULR+"/img/sharebt.png' alt=''/></span>");
		}
	}

//fix IE
if (!window.location.origin) {
	  window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
	}